+2006-09-03 Kristian Rietveld <kris@imendio.com>
+
+ * gtk/gtkfilechooserdefault.c (save_entry_get_info_cb),
+ (file_exists_get_info_cb), (gtk_file_chooser_default_should_respond):
+ change file_exists_and_is_not_folder checks to get the file info
+ for the path directly instead of querying the current file folder
+ of the save entry.
+
+ * gtk/gtkfilechooserprivate.h (struct _GtkFileChooserDefault): add
+ new field.
+
+ * tests/autotestfilechooser.c (wait_for_idle_idle), (wait_for_idle),
+ (test_reload_sequence), (test_button_folder_states_for_action): wait
+ for idle after setting a folder to ensure the async operations to load
+ the folder are finished,
+ (test_confirm_overwrite), (test_confirm_overwrite_for_path):
+ factor out test_confirm_overwrite code so we can add tests for more
+ paths more easily.
+
2006-09-03 Richard Hult <richard@imendio.com>
* gdk/quartz/GdkQuartzView.c (drawRect): Don't do anything if
g_object_unref (handle);
}
-struct SaveEntryData
+struct FileExistsData
{
GtkFileChooserDefault *impl;
gboolean file_exists_and_is_not_folder;
{
gboolean parent_is_folder;
gboolean cancelled = handle->cancelled;
- struct SaveEntryData *data = user_data;
+ struct FileExistsData *data = user_data;
if (handle != data->impl->should_respond_get_info_handle)
goto out;
g_object_unref (handle);
}
+static void
+file_exists_get_info_cb (GtkFileSystemHandle *handle,
+ const GtkFileInfo *info,
+ const GError *error,
+ gpointer user_data)
+{
+ gboolean data_ownership_taken = FALSE;
+ gboolean cancelled = handle->cancelled;
+ gboolean file_exists_and_is_not_folder;
+ struct FileExistsData *data = user_data;
+
+ if (handle != data->impl->file_exists_get_info_handle)
+ goto out;
+
+ data->impl->file_exists_get_info_handle = NULL;
+
+ set_busy_cursor (data->impl, FALSE);
+
+ if (cancelled)
+ goto out;
+
+ file_exists_and_is_not_folder = info && !gtk_file_info_get_is_folder (info);
+
+ if (data->impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
+ /* user typed a filename; we are done */
+ g_signal_emit_by_name (data->impl, "response-requested");
+ else if (data->impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER
+ && file_exists_and_is_not_folder)
+ {
+ /* Oops, the user typed the name of an existing path which is not
+ * a folder
+ */
+ error_creating_folder_over_existing_file_dialog (data->impl, data->path,
+ g_error_copy (error));
+ }
+ else
+ {
+ /* check that everything up to the last component exists */
+
+ data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
+ data_ownership_taken = TRUE;
+
+ if (data->impl->should_respond_get_info_handle)
+ gtk_file_system_cancel_operation (data->impl->should_respond_get_info_handle);
+
+ data->impl->should_respond_get_info_handle =
+ gtk_file_system_get_info (data->impl->file_system,
+ data->parent_path,
+ GTK_FILE_INFO_IS_FOLDER,
+ save_entry_get_info_cb,
+ data);
+ set_busy_cursor (data->impl, TRUE);
+ }
+
+out:
+ if (!data_ownership_taken)
+ {
+ g_object_unref (data->impl);
+ gtk_file_path_free (data->path);
+ gtk_file_path_free (data->parent_path);
+ g_free (data);
+ }
+
+ g_object_unref (handle);
+}
+
static void
paste_text_received (GtkClipboard *clipboard,
const gchar *text,
}
else
{
- gboolean file_exists_and_is_not_folder;
-
- file_exists_and_is_not_folder = g_error_matches (error, GTK_FILE_SYSTEM_ERROR, GTK_FILE_SYSTEM_ERROR_NOT_FOLDER);
-
- if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN)
- retval = TRUE; /* user typed a filename; we are done */
- else if (impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER && file_exists_and_is_not_folder)
- {
- /* Oops, the user typed the name of an existing path which is not a folder */
- error_creating_folder_over_existing_file_dialog (impl, path, error);
- error = NULL; /* as it will be freed below for the general case */
- retval = FALSE;
- }
- else
- {
- GtkFilePath *parent_path;
- struct SaveEntryData *data;
-
- /* check that everything up to the last component exists */
+ struct FileExistsData *data;
- parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
+ /* We need to check whether path exists and is not a folder */
- data = g_new0 (struct SaveEntryData, 1);
- data->impl = g_object_ref (impl);
- data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
- data->parent_path = parent_path; /* Takes ownership */
- data->path = gtk_file_path_copy (path);
+ data = g_new0 (struct FileExistsData, 1);
+ data->impl = g_object_ref (impl);
+ data->path = gtk_file_path_copy (path);
+ data->parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
- if (impl->should_respond_get_info_handle)
- gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
+ if (impl->file_exists_get_info_handle)
+ gtk_file_system_cancel_operation (impl->file_exists_get_info_handle);
- impl->should_respond_get_info_handle =
- gtk_file_system_get_info (impl->file_system, parent_path,
- GTK_FILE_INFO_IS_FOLDER,
- save_entry_get_info_cb,
- data);
- set_busy_cursor (impl, TRUE);
+ impl->file_exists_get_info_handle =
+ gtk_file_system_get_info (impl->file_system, path,
+ GTK_FILE_INFO_IS_FOLDER,
+ file_exists_get_info_cb,
+ data);
- retval = FALSE;
- }
+ set_busy_cursor (impl, TRUE);
+ retval = FALSE;
if (error != NULL)
g_error_free (error);
GtkFileSystemHandle *update_current_folder_handle;
GtkFileSystemHandle *show_and_select_paths_handle;
GtkFileSystemHandle *should_respond_get_info_handle;
+ GtkFileSystemHandle *file_exists_get_info_handle;
GtkFileSystemHandle *update_from_entry_handle;
GtkFileSystemHandle *shortcuts_activate_iter_handle;
GSList *pending_handles;
return FALSE;
}
+
+static guint wait_for_idle_id = 0;
+
+static gboolean
+wait_for_idle_idle (gpointer data)
+{
+ wait_for_idle_id = 0;
+
+ return FALSE;
+}
+
+static void
+wait_for_idle (void)
+{
+ wait_for_idle_id = g_idle_add_full (G_PRIORITY_LOW + 100,
+ wait_for_idle_idle,
+ NULL, NULL);
+
+ while (wait_for_idle_id)
+ gtk_main_iteration ();
+}
+
static gboolean
test_set_filename (GtkFileChooserAction action,
gboolean focus_button,
/* http://bugzilla.gnome.org/show_bug.cgi?id=347883 */
static gboolean
-test_confirm_overwrite (void)
+test_confirm_overwrite_for_path (const char *path)
{
gboolean passed;
struct confirm_overwrite_closure closure;
g_signal_connect (closure.chooser, "confirm-overwrite",
G_CALLBACK (confirm_overwrite_cb), &closure);
- gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (closure.chooser), "/etc/passwd"); /* a file we know will always exist */
+ gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (closure.chooser), path);
g_timeout_add (2000, confirm_overwrite_timeout_cb, &closure);
gtk_dialog_run (GTK_DIALOG (closure.chooser));
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (closure.chooser));
- passed = passed && filename && (strcmp (filename, "/etc/passwd") == 0);
+ passed = passed && filename && (strcmp (filename, path) == 0);
g_free (filename);
gtk_widget_destroy (closure.chooser);
return passed;
}
+static gboolean
+test_confirm_overwrite (void)
+{
+ gboolean passed = TRUE;
+
+ passed = passed && test_confirm_overwrite_for_path ("/etc/passwd"); /* a file we know will always exist */
+
+ return passed;
+}
+
static const GtkFileChooserAction open_actions[] = {
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
{
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), g_get_home_dir ());
+ wait_for_idle ();
+
passed = passed && (impl->current_folder != NULL
&& impl->browse_files_model != NULL
&& (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
? (impl->load_timeout_id == 0 && impl->sort_model != NULL)
: TRUE));
+ wait_for_idle ();
+
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
passed = passed && (folder != NULL && strcmp (folder, g_get_home_dir()) == 0);
g_free (folder);
&& impl->reload_state == RELOAD_EMPTY
&& impl->load_timeout_id == 0);
+ wait_for_idle ();
+
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
passed = passed && (folder != NULL && strcmp (folder, current_working_dir) == 0);
}
gtk_widget_show_now (dialog);
+ wait_for_idle ();
+
passed = passed && (impl->current_folder != NULL
&& impl->browse_files_model != NULL
&& (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
gtk_widget_hide (dialog);
+ wait_for_idle ();
+
passed = passed && (impl->current_folder != NULL
&& impl->browse_files_model != NULL
&& (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
gtk_widget_show_now (dialog);
+ wait_for_idle ();
+
passed = passed && (impl->current_folder != NULL
&& impl->browse_files_model != NULL
&& (impl->load_state == LOAD_PRELOAD || impl->load_state == LOAD_LOADING || impl->load_state == LOAD_FINISHED)
gtk_container_add (GTK_CONTAINER (window), button);
/* Pre-map; no folder is set */
+ wait_for_idle ();
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
if (must_have_cwd)
gtk_widget_show_all (window);
gtk_widget_show_now (window);
+
+ wait_for_idle ();
+
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
if (must_have_cwd)
/* Unmap; folder should be set */
gtk_widget_hide (window);
+ wait_for_idle ();
folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (button));
if (must_have_cwd)
passed = passed && (folder != NULL && strcmp (folder, current_working_dir) == 0);
else
passed = passed && (folder != NULL && strcmp (folder, g_get_home_dir()) == 0);
-
+ wait_for_idle ();
log_test (passed, "test_button_folder_states_for_action(): %s, use_dialog=%d, set_folder_on_dialog=%d, re-mapped, %s",
get_action_name (action),
use_dialog,